package com.ybb.production.service.impl;

import com.ybb.production.domain.GarmentProductionBianfei;
import com.ybb.production.domain.GarmentProductionCuttingBedInfo;
import com.ybb.production.domain.GarmentProductionOrder;
import com.ybb.production.domain.GarmentProductionProcess;
import com.ybb.production.dto.GarmentProductionCuttindBedQueryDTO;
import com.ybb.production.dto.GarmentProductionCuttingBedDTO;
import com.ybb.production.dto.GarmentProductionCuttingBedUpdateDTO;
import com.ybb.production.mapper.GarmentProductionBianfeiMapper;
import com.ybb.production.mapper.GarmentProductionCuttingBedInfoMapper;
import com.ybb.production.mapper.GarmentProductionProcessMapper;
import com.ybb.production.responce.*;
import com.ybb.production.service.IGarmentProductionCuttingBedInfoService;
import com.yubb.common.constant.CacheConstants;
import com.yubb.common.core.redis.RedisCache;
import com.yubb.common.exception.GlobalException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import javax.validation.Valid;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 裁单信息Service业务层处理
 *
 * @author ruoyi
 * @date 2023-09-09
 */
@Service
@Slf4j
public class GarmentProductionCuttingBedInfoServiceImpl implements IGarmentProductionCuttingBedInfoService {
    @Autowired
    private GarmentProductionCuttingBedInfoMapper garmentProductionCuttingBedInfoMapper;

    @Autowired
    private GarmentProductionBianfeiServiceImpl garmentProductionBianfeiService;

    @Autowired
    private GarmentProductionBianfeiMapper garmentProductionBianfeiMapper;

    @Autowired
    private GarmentProductionProcessServiceImpl garmentProductionProcessService;

    @Autowired
    private GarmentProductionOrderServiceImpl garmentProductionOrderService;

    @Autowired
    private RedisCache redisCache;

    @Autowired
    private GarmentProductionProcessMapper garmentProductionProcessMapper;


    /**
     * 查询裁单信息
     *
     * @param id 裁单信息主键
     * @return 裁单信息
     */
    @Override
    public GarmentBianfeiByBundleResp selectGarmentProductionCuttingBedInfoById(Long id) {
        List<GarmentBianfeiCompleteDetailResp> bianfeis = garmentProductionProcessService.selectListByBundleNoAndBleNo(id);
        int sum = bianfeis.stream().mapToInt(GarmentBianfeiCompleteDetailResp::getCuttingBedQuantity).sum();
        GarmentBianfeiByBundleResp resp = new GarmentBianfeiByBundleResp();
        GarmentProductionCuttingBedInfo bedInfo = garmentProductionCuttingBedInfoMapper.selectGarmentProductionCuttingBedInfoById(id);
        BeanUtils.copyProperties(bedInfo, resp);
        resp.setTotalBundle(bianfeis.size());
        resp.setCuttingBedQuantity(sum);
        resp.setDetailList(bianfeis);
        resp.setCuttindbedId(id);
        GarmentProductionOrder order = garmentProductionOrderService.selectGarmentProductionOrderById(bedInfo.getOrderId());
        resp.setStyleCode(order.getStyleCode());
        resp.setOrderId(order.getId());
        return resp;
    }

    /**
     * 查询裁单信息列表
     *
     * @param bedInfo 裁单信息
     * @return 裁单信息
     */
    @Override
    public List<GarmentProductionCuttingBedPageResp> selectGarmentProductionCuttingBedInfoList(GarmentProductionCuttindBedQueryDTO bedInfo) {
        try {
            List<GarmentProductionCuttingBedPageResp> resps = garmentProductionCuttingBedInfoMapper.selectGarmentProductionCuttingBedInfoList(bedInfo);
            if (CollectionUtils.isEmpty(resps)) {
                return new ArrayList<>();
            }
            Set<Long> cuttingIds = resps.stream().map(GarmentProductionCuttingBedPageResp::getId).collect(Collectors.toSet());
            // 查询裁单数量
            List<Map<String, Object>> cutCntList = garmentProductionBianfeiService.selectGarmentProductionBianfeiListByCuttingId(cuttingIds);
            Map<String, Object> cutCntMap = cutCntList.stream().collect(Collectors.toMap(item -> item.get("cuttindbedId").toString(), item -> item.get("quantity")));
            // 查询完成件数：先查最后一道工序是什么，然后查询上数记录查看是否完成最后一道工序，完成了就算完成件数+1
            Set<Long> orderIdss = resps.stream().map(GarmentProductionCuttingBedPageResp::getOrderId).collect(Collectors.toSet());
            List<Map<String, Object>> lastProcessMap = garmentProductionProcessService.selectGarmentProductionProcessLastProcess(orderIdss);
            // 获取最后一道工序的list
            List<Long> lastProcessIds = new ArrayList<>();
            if (!CollectionUtils.isEmpty(lastProcessMap)) {
                lastProcessIds = lastProcessMap.stream().map(item -> Long.parseLong(item.get("id").toString())).collect(Collectors.toList());
            }
            Map<Long, Long> completeMap = new HashMap<>();
            // 查询上数记录是否有最后一道工序，有就算完成
            if (!CollectionUtils.isEmpty(lastProcessIds)) {
                List<Long> cuttingIdss = garmentProductionBianfeiService.selectGarmentProductionBianfeiListByProcessIds(lastProcessIds);
                if (!CollectionUtils.isEmpty(cuttingIdss)) {
                    List<GarmentProductionBianfei> bianfeilist = garmentProductionBianfeiService.qryBianFeiSum(cuttingIdss, lastProcessIds);
                    if (!CollectionUtils.isEmpty(bianfeilist)) {
                        completeMap = bianfeilist.stream().collect(Collectors.toMap(GarmentProductionBianfei::getCuttindbedId, GarmentProductionBianfei::getQuantity));
                    }
                }
            }
            // 查询工序数
            List<Map<String, Object>> processCntList2 = garmentProductionProcessService.processCnt(orderIdss);
            Map<String, Object> processCntMap = processCntList2.stream().collect(Collectors.toMap(item -> item.get("orderId").toString(), item -> item.get("processCnt")));
            List<GarmentBianfeiSumResp> bianfeiStaList = garmentProductionBianfeiMapper.qryTotalAndCompleteByCuttingBedIds(new ArrayList<>(cuttingIds), null);
            Map<Long, GarmentBianfeiSumResp> bianfeiStaMap = bianfeiStaList.stream().collect(Collectors.toMap(GarmentBianfeiSumResp::getCuttindbedId, bianfeiSumResp -> bianfeiSumResp));

            for (GarmentProductionCuttingBedPageResp resp : resps) {
                if (cutCntMap.get(resp.getId().toString()) != null && Objects.nonNull(processCntMap.get(resp.getOrderId().toString()))) {
                    // 完成件数除以工序数
                    long processCnt = Long.parseLong(processCntMap.get(resp.getOrderId().toString()).toString());
                    resp.setCutQuantity(String.valueOf(Long.parseLong(cutCntMap.get(resp.getId().toString()).toString()) / processCnt));
                } else {
                    resp.setCutQuantity("0");
                }
                if (completeMap.get(resp.getId()) != null) {
                    // 裁单完成件数
                    resp.setCompleteQuantity(completeMap.get(resp.getId()).toString());
                } else {
                    resp.setCompleteQuantity("0");
                }
                if (bianfeiStaMap.get(resp.getId()) != null) {
                    // 工序数 = 完成件数 * 工序数
                    resp.setProcessQuantity(bianfeiStaMap.get(resp.getId()).getTotalQuantity());
                } else {
                    resp.setProcessQuantity("0");
                }
                if (bianfeiStaMap.get(resp.getId()) != null) {
                    // 完成工序数 = 裁单完成件数 * 工序数
                    resp.setProcessCompleteQuantity(bianfeiStaMap.get(resp.getId()).getCompleteQuantity());
                } else {
                    resp.setProcessCompleteQuantity("0");
                }
            }

            return resps;
        } catch (Exception e) {
            log.error("查询裁单信息列表失败", e);
            throw new GlobalException("查询裁单信息列表失败");
        }
    }

    /**
     * 新增裁单信息
     *
     * @param bedDTO 裁单信息
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public GarmentProductionCuttingBedInfo insertGarmentProductionCuttingBedInfo(@Valid GarmentProductionCuttingBedDTO bedDTO) {
        bedDTO.setDelFlag("0");
        // 1. 新增裁单信息
        GarmentProductionCuttingBedInfo bedInfo = new GarmentProductionCuttingBedInfo();
        BeanUtils.copyProperties(bedDTO, bedInfo);
        // 1.1 没有填床号就从redis取自增的床号
        if (bedInfo.getbedNo() == null) {
            Long bedNo = redisCache.incrementCounter(CacheConstants.bed_no_INCR);
            bedInfo.setbedNo(bedNo.toString());
        }
        garmentProductionCuttingBedInfoMapper.insertGarmentProductionCuttingBedInfo(bedInfo);
        GarmentProductionProcess productionProcess = new GarmentProductionProcess();
        productionProcess.setOrderId(bedDTO.getOrderId());
        // 查询工序列表
        List<GarmentProductionProcess> garmentProductionProcesses = garmentProductionProcessService.selectGarmentProductionProcessList(productionProcess);
        // 2. 新增编菲信息
        List<GarmentProductionCuttingBedDTO.BianfeiDTO> bianfeiList = bedDTO.getBianfeiList();
        // 2.1 计算总数
        long total = 0L;
        List<GarmentProductionBianfei> insertList = new ArrayList<>();
        for (GarmentProductionCuttingBedDTO.BianfeiDTO bianfeiDTO : bianfeiList) {
            for (GarmentProductionProcess process : garmentProductionProcesses) {
                GarmentProductionBianfei bianfei = new GarmentProductionBianfei();
                BeanUtils.copyProperties(bedDTO, bianfei);
                BeanUtils.copyProperties(bianfeiDTO, bianfei);
                bianfei.setOrderId(bedDTO.getOrderId());
                bianfei.setCuttindbedId(bedInfo.getId());
                bianfei.setProcessId(process.getId());
                bianfei.setStatus(0L);
                bianfei.setInitialQuantity(bianfeiDTO.getQuantity());
                bianfei.setSettlementStatus(0L);
                bianfei.setPayStatus(0L);
                insertList.add(bianfei);
            }
            // 如果insertList的size大于1000，就批量插入
            if (insertList.size() >= 1000) {
                garmentProductionBianfeiService.batchInsert(insertList);
                insertList.clear();
            }
            total = total + bianfeiDTO.getQuantity();
        }
        // 处理最后一次不足1000的数据
        if (!insertList.isEmpty()) {
            garmentProductionBianfeiService.batchInsert(insertList);
            insertList.clear();
        }
//        // 3. 更新工序数量
//        garmentProductionProcessService.updateProcessQuantityByOrderId(bedDTO.getOrderId(), total);
        // 4. 更新生产单的床号
        GarmentProductionOrder order = garmentProductionOrderService.selectGarmentProductionOrderById(bedDTO.getOrderId());
        buildBedNo(order, bedInfo.getbedNo());
        garmentProductionOrderService.updateGarmentProductionOrderbedNo(order.getId(), order.getBedNo());
        return bedInfo;
    }

    private void buildBedNo(GarmentProductionOrder order, String bedNo) {
        if (order.getBedNo() == null) {
            order.setBedNo("");
        }
        List<String> bedNoList = Arrays.asList(order.getBedNo().split(","));
        Set<String> bedNoSet = new HashSet<>(bedNoList);
        bedNoSet.remove("");
        bedNoSet.add(bedNo);
        String bedNoRe = String.join(",", bedNoSet);
        order.setBedNo(bedNoRe);
    }

    /**
     * 修改裁单信息
     *
     * @param bedUpdateDTO 裁单信息
     * @return 结果
     */
    @Override
    public int updateGarmentProductionCuttingBedInfo(GarmentProductionCuttingBedUpdateDTO bedUpdateDTO) {
        // 1. 更新裁单信息
        GarmentProductionCuttingBedInfo bedInfo = new GarmentProductionCuttingBedInfo();
        BeanUtils.copyProperties(bedUpdateDTO, bedInfo);

        // 2. 更新生产单的床号
        GarmentProductionOrder order = garmentProductionOrderService.selectGarmentProductionOrderById(bedUpdateDTO.getOrderId());
        buildBedNo(order, bedInfo.getbedNo());
        garmentProductionOrderService.updateGarmentProductionOrderbedNo(bedUpdateDTO.getOrderId(), bedInfo.getbedNo());

        return garmentProductionCuttingBedInfoMapper.updateGarmentProductionCuttingBedInfo(bedInfo);
    }

    /**
     * 批量删除裁单信息
     *
     * @param ids 需要删除的裁单信息主键
     * @return 结果
     */
    @Override
    public int deleteGarmentProductionCuttingBedInfoByIds(Long[] ids) {
        garmentProductionBianfeiService.deleteGarmentProductionBianfeiByCuttingBedIds(ids);
        return garmentProductionCuttingBedInfoMapper.deleteGarmentProductionCuttingBedInfoByIds(ids);
    }

    /**
     * 删除裁单信息信息
     *
     * @param id 裁单信息主键
     * @return 结果
     */
    @Override
    public int deleteGarmentProductionCuttingBedInfoById(Long id) {
        return garmentProductionCuttingBedInfoMapper.deleteGarmentProductionCuttingBedInfoById(id);
    }

    @Override
    public GarmentProductionCuttingBedPageResp qryCuttingBedStatistics() {
        GarmentProductionCuttingBedPageResp resp = new GarmentProductionCuttingBedPageResp();
        int completeCnt = 0;
        List<Long> lastProcessIds = new ArrayList<>();
        List<Map<String, Object>> lastProcessMap = garmentProductionProcessService.selectGarmentProductionProcessLastProcess(null);
        if (!CollectionUtils.isEmpty(lastProcessMap)) {
            lastProcessIds = lastProcessMap.stream().map(item -> Long.parseLong(item.get("id").toString())).collect(Collectors.toList());
        }
        // 查询上数记录是否有最后一道工序，有就算完成
        if (!CollectionUtils.isEmpty(lastProcessIds)) {
            List<Long> cuttingIdss = garmentProductionBianfeiService.selectGarmentProductionBianfeiListByProcessIds(lastProcessIds);
            if (!CollectionUtils.isEmpty(cuttingIdss)) {
                List<GarmentProductionBianfei> bianfeilist = garmentProductionBianfeiService.qryBianFeiSum(cuttingIdss, lastProcessIds);
                // 遍历获取quantity求和
                for (GarmentProductionBianfei bianfei : bianfeilist) {
                    completeCnt = completeCnt + bianfei.getQuantity().intValue();
                }
            }
        }
        int allCnt = garmentProductionBianfeiService.qryAllCuttingBedCnt();
        resp.setCompleteQuantity(String.valueOf(completeCnt));
        resp.setCutQuantity(String.valueOf(allCnt));
        return resp;
    }

    @Override
    public GarmentProductionCuttingBedPageResp getCuttingBedStatisticsResult(Long cuttingBedId) {
        GarmentProductionCuttingBedPageResp resp = new GarmentProductionCuttingBedPageResp();
        GarmentProductionCuttingBedInfo bedInfo = garmentProductionCuttingBedInfoMapper.selectGarmentProductionCuttingBedInfoById(cuttingBedId);

        resp.setId(bedInfo.getId());
        resp.setBedNo(bedInfo.getbedNo());
        resp.setCompleteQuantity("0");
        resp.setProcessQuantity("0");
        resp.setProcessCompleteQuantity("0");

        // 查询最后一道工序
        List<Map<String, Object>> maps = garmentProductionProcessService.selectGarmentProductionProcessLastProcess(Stream.of(bedInfo.getOrderId())
                .collect(Collectors.toSet()));
        Map<Long, Long> completeMap = new HashMap<>();
        Long lastProcess = null;
        if (!CollectionUtils.isEmpty(maps)) {
            lastProcess = Long.parseLong(maps.get(0).get("id").toString());
            List<Long> ids = Stream.of(lastProcess).collect(Collectors.toList());
            List<Long> cuttingIdss = garmentProductionBianfeiService.selectGarmentProductionBianfeiListByProcessIds(ids);
            if (!CollectionUtils.isEmpty(cuttingIdss)) {
                List<GarmentProductionBianfei> bianfeilist = garmentProductionBianfeiService.qryBianFeiSum(cuttingIdss, ids);
                completeMap = bianfeilist.stream().collect(Collectors.toMap(GarmentProductionBianfei::getCuttindbedId, GarmentProductionBianfei::getQuantity));
            }
        }
        if (completeMap.get(bedInfo.getId()) != null) {
            // 裁单完成件数
            resp.setCompleteQuantity(completeMap.get(bedInfo.getId()).toString());
        }

        // 查询工序数和完成工序数
        List<GarmentBianfeiSumResp> bianfeiList = garmentProductionBianfeiMapper.qryTotalAndCompleteByCuttingBedIds(Collections.singletonList(bedInfo.getId()), null);
        Map<Long, GarmentBianfeiSumResp> bianfeiMap = bianfeiList.stream().collect(Collectors.toMap(GarmentBianfeiSumResp::getCuttindbedId, bianfeiSumResp -> bianfeiSumResp));
        if (bianfeiMap.get(bedInfo.getId()) != null) {
            resp.setProcessQuantity(bianfeiMap.get(bedInfo.getId()).getTotalQuantity());
            resp.setProcessCompleteQuantity(bianfeiMap.get(bedInfo.getId()).getCompleteQuantity());
        }

        // 构建列表
        if (Objects.isNull(lastProcess)) {
            return resp;
        }
        List<GarmentBianfeiCompleteDetailResp> detailList = new ArrayList<>();
        GarmentProductionBianfei bianfei = new GarmentProductionBianfei();
        bianfei.setId(bedInfo.getId());
        bianfei.setProcessId(lastProcess);
        List<GarmentProductionBianfei> result = garmentProductionBianfeiMapper.qryListSingle(bianfei);
        if (!CollectionUtils.isEmpty(result)) {
            for (GarmentProductionBianfei productionBianfei : result) {
                GarmentBianfeiCompleteDetailResp detailResp = new GarmentBianfeiCompleteDetailResp();
                detailResp.setBoltNo(productionBianfei.getBoltNo());
                detailResp.setBundleNo(String.valueOf(productionBianfei.getBundleNo()));
                detailResp.setColor(productionBianfei.getColor());
                detailResp.setSize(productionBianfei.getSize());
                detailResp.setCuttingBedQuantity(Math.toIntExact(productionBianfei.getQuantity()));
                detailResp.setCompleteQuantity(Objects.isNull(productionBianfei.getUpNumber()) ? 0 : Math.toIntExact(productionBianfei.getUpNumber()));
                detailResp.setRemainderQuantity(detailResp.getCuttingBedQuantity() - detailResp.getCompleteQuantity());
                detailList.add(detailResp);
            }
        }
        resp.setDetail(detailList);
        return resp;
    }

    @Override
    public List<GarmentProductionCuttingBedByBoltResp> garmentProductionCuttingBedByBoltResp(Long cuttingBedId) {
        List<GarmentProductionCuttingBedByBoltResp> resps = new ArrayList<>();
        GarmentProductionBianfei bianfei = new GarmentProductionBianfei();
        bianfei.setCuttindbedId(cuttingBedId);
        List<GarmentProductionBianfei> bainfeis = garmentProductionBianfeiMapper.selectGarmentProductionBianfeiList(bianfei);

        Map<Long,Long> totalProcessMap = new HashMap<>();
        Map<Long,Long> totalCompletedProcessMap = new HashMap<>();
        for (GarmentProductionBianfei bainfei : bainfeis) {
            if (Objects.isNull(totalProcessMap.get(bainfei.getBundleNo()))) {
                totalProcessMap.put(bainfei.getBundleNo(), bainfei.getQuantity());
            } else {
                Long quantity = Objects.isNull(bainfei.getQuantity()) ? 0L : bainfei.getQuantity();
                totalProcessMap.put(bainfei.getBundleNo(), totalProcessMap.get(bainfei.getBundleNo()) + quantity);
            }
            if (Objects.isNull(totalCompletedProcessMap.get(bainfei.getBundleNo()))) {
                totalCompletedProcessMap.put(bainfei.getBundleNo(), bainfei.getUpNumber());
            } else {
                Long upNumber = Objects.isNull(bainfei.getUpNumber()) ? 0L : bainfei.getUpNumber();
                totalCompletedProcessMap.put(bainfei.getBundleNo(), totalCompletedProcessMap.get(bainfei.getBundleNo()) + upNumber);
            }
        }

        for (GarmentProductionBianfei bainfei : bainfeis) {
            boolean exists = resps.stream().anyMatch(obj -> Objects.equals(obj.getBundleNo(), bainfei.getBundleNo()));
            if (exists) {
                GarmentProductionCuttingBedByBoltResp resp = resps.stream().filter(obj -> Objects.equals(obj.getBundleNo(), bainfei.getBundleNo())).findFirst().get();
                List<GarmentProductionCuttingBedByBoltResp.ProcessDetail> detail = resp.getDetail();
                buildDetail(detail, bainfei);
                continue;
            }
            GarmentProductionCuttingBedByBoltResp resp = new GarmentProductionCuttingBedByBoltResp();
            resp.setId(bainfei.getId());
            resp.setCuttingBedId(bianfei.getCuttindbedId());
            resp.setBundleNo(bainfei.getBundleNo());
            resp.setColor(bainfei.getColor());
            resp.setSize(bainfei.getSize());
            resp.setQuantity(bainfei.getQuantity());
            resp.setTotalProcess(totalProcessMap.get(bainfei.getBundleNo()));
            resp.setTotalCompletedProcess(totalCompletedProcessMap.get(bainfei.getBundleNo()));
            List<GarmentProductionCuttingBedByBoltResp.ProcessDetail> detail = new ArrayList<>();
            buildDetail(detail, bainfei);
            resp.setDetail(detail);
            resps.add(resp);
        }
        return resps;
    }

    @Override
    public int editQuery(GarmentProductionBianfei garmentProductionBianfei) {
        GarmentProductionBianfei query = new GarmentProductionBianfei();
        query.setCuttindbedId(garmentProductionBianfei.getCuttindbedId());
        query.setBundleNo(garmentProductionBianfei.getBundleNo());
        if (Objects.nonNull(garmentProductionBianfei.getProcessId())) {
            query.setProcessId(garmentProductionBianfei.getProcessId());
        }
        List<GarmentProductionBianfei> garmentProductionBianfeis = garmentProductionBianfeiMapper.selectGarmentProductionBianfeiList(query);
        if (CollectionUtils.isEmpty(garmentProductionBianfeis)) {
            throw new GlobalException("未查询到裁单信息");
        }
        for (GarmentProductionBianfei productionBianfei : garmentProductionBianfeis) {
            GarmentProductionBianfei update = new GarmentProductionBianfei();
            update.setId(productionBianfei.getId());
            if (Objects.nonNull(garmentProductionBianfei.getProcessId())) {
                update.setQuantity(garmentProductionBianfei.getQuantity());
            } else {
                update.setInitialQuantity(garmentProductionBianfei.getQuantity());
            }
            update.setRemark(garmentProductionBianfei.getRemark());
            garmentProductionBianfeiMapper.updateGarmentProductionBianfei(update);
        }
        return 1;
    }

    @Override
    public List<GarmentProductionProgressByBedNoResp.CuttingBedProcess> getCuttingBedByProcess(Long cuttingBedId) {
        // 1. 查询裁床信息
        GarmentProductionCuttingBedInfo bedInfos = garmentProductionCuttingBedInfoMapper.selectGarmentProductionCuttingBedInfoById(cuttingBedId);
        // 查询工序数量
        GarmentProductionProcess process = new GarmentProductionProcess();
        process.setOrderId(bedInfos.getOrderId());
        List<GarmentProductionProcess> processList = garmentProductionProcessMapper.selectGarmentProductionProcessList(process);
        // 查询按工序纬度统计结果
        List<GarmentBianfeiSumResp> bianfeiByProcess = garmentProductionBianfeiMapper.qryGroupByProcess(Collections.singletonList(cuttingBedId));
        Map<Long, List<GarmentBianfeiSumResp>> bianfeiByProcessMap = bianfeiByProcess.stream().collect(Collectors.groupingBy(GarmentBianfeiSumResp::getProcessId));

        // 查询完成详情
        List<GarmentProductionProgressByBedNoResp.CuttingBedProcess> cuttingBedProcessList = new ArrayList<>();
        for (GarmentProductionProcess productionProcess : processList) {
            GarmentBianfeiSumResp garmentBianfeiSumResp = bianfeiByProcessMap.get(productionProcess.getId()).get(0);
            GarmentProductionProgressByBedNoResp.CuttingBedProcess cuttingBedProcess = new GarmentProductionProgressByBedNoResp.CuttingBedProcess();
            cuttingBedProcess.setCuttingBedId(bedInfos.getId());
            cuttingBedProcess.setProcessName(productionProcess.getProcessName());
            cuttingBedProcess.setPrice(productionProcess.getPrice());
            cuttingBedProcess.setTotalQuantity(Long.valueOf(garmentBianfeiSumResp.getTotalQuantity()));
            cuttingBedProcess.setCompleteQuantity(Long.valueOf(garmentBianfeiSumResp.getCompleteQuantity()));
            cuttingBedProcess.setRemainderQuantity(cuttingBedProcess.getTotalQuantity() - cuttingBedProcess.getCompleteQuantity());
            cuttingBedProcess.setProcessId(productionProcess.getId());
            cuttingBedProcessList.add(cuttingBedProcess);
        }
        return cuttingBedProcessList;
    }

    private void buildDetail(List<GarmentProductionCuttingBedByBoltResp.ProcessDetail> detail, GarmentProductionBianfei bainfei) {
        GarmentProductionCuttingBedByBoltResp.ProcessDetail processDetail = new GarmentProductionCuttingBedByBoltResp.ProcessDetail();
        processDetail.setProcessId(bainfei.getProcessId());
        processDetail.setProcessName(bainfei.getProcessName());
        processDetail.setPrice(bainfei.getProcessPrice());
        processDetail.setProcessStatus(bainfei.getStatus().toString());
        processDetail.setProcessCompleteTime(bainfei.getUpdateTime());
        processDetail.setUpdateBy(bainfei.getUpId());
        processDetail.setUpdateByName(bainfei.getUpUserName());
        processDetail.setRemark(bainfei.getRemark());
        detail.add(processDetail);
    }
}
